/**
 * 
 */
package com.wsj.web.action.homeSiteNews;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.wsj.service.IHomeSiteAdBannerDescriptServ;
import com.wsj.service.IHomeSiteAdBannerServ;
import com.wsj.service.IHomeSiteNewsClassServ;
import com.wsj.service.IHomeSiteNewsServ;
import com.wsj.service.IUserManagerServ;
import com.wsj.util.page.PageResultSet;
import com.wsj.util.tool.HtmlCreateObj;
import com.wsj.util.tool.RequestUtils;
import com.wsj.web.action.BaseAction;
import com.wsj.web.constant.homeSiteNews.HomeSiteNewsConstant;
import com.wsj.web.constant.homeSiteNews.IndexPageContent;
import com.wsj.web.vo.homeSite.HomeSiteNews;
import com.wsj.web.vo.homeSite.HomeSiteNewsClass;

/**
 * @author fengbin  createTime:2009-8-8
 * 
 * 批量创建关于我们的html页面
 */
public class HomeSiteAboutMeAction extends BaseAction {
	
	
//	生成html页面对象
	private HtmlCreateObj htmlCreateObj;

	/** 资讯分类接口 */
	private IHomeSiteNewsClassServ homeSiteNewsClassServ;
	
	/** 资讯接口 */
	private IHomeSiteNewsServ homeSiteNewsServImpl;
	
	/******
	 * 用户接口
	 */
	private IUserManagerServ userManagerServ;
	
	
	
	
	/*****
	 * 批量生成关于我们页面的静态页面
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward batchCreateAboutMePage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		 HomeSiteNewsClass   homeSiteNewsClass = this.getHomeSiteNewsClassServ().loadNewsClassByNames(IndexPageContent.KNOW_ME_NAME);
		 if(homeSiteNewsClass!=null){
			 //获取下面所有的新闻.
			 PageResultSet pageResultSet = homeSiteNewsServImpl.loadByClassId(homeSiteNewsClass.getId(), 1, 1000);
			 if(pageResultSet!=null){
				 List<HomeSiteNews> homeSiteNewsList =  pageResultSet.getResult();
				 if(homeSiteNewsList!=null  && !homeSiteNewsList.isEmpty()){
					 for(HomeSiteNews homeSiteNews:homeSiteNewsList){
						 //生成静态页面
						String filePath=HomeSiteNewsConstant.homeSiteNewsHead+homeSiteNews.getId()+".html";
						htmlCreateObj.setCreateFileParament(RequestUtils.getRequestHost(request)+HomeSiteNewsConstant.homeSiteAboutMePath+homeSiteNews.getId(), "html/about/", filePath);
						 //生成静态页面
						htmlCreateObj.createHtmlFile(request, response);
						homeSiteNews.setFilePath(filePath);
						this.getHomeSiteNewsServImpl().update(homeSiteNews);
						
					 }
				 }
			 }
			 
		 }
		
		 request.setAttribute("msg", "批量生成完成");
		
		 return mapping.findForward("success");
	}
	
	
	/********
	 * 通过id获取页面
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward loadPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		 
		 String id = request.getParameter("id");
		 if(id!=null  && !id.equals("")){
		  HomeSiteNews	homeSiteNews  = this.getHomeSiteNewsServImpl().getHomeSiteNewsById(Long.valueOf(id));
		  request.setAttribute("homeSiteNews", homeSiteNews);
		 }
		 
		 return mapping.findForward("aboutMe");
	}
		
		



	public IHomeSiteNewsClassServ getHomeSiteNewsClassServ() {
		return homeSiteNewsClassServ;
	}



	public void setHomeSiteNewsClassServ(
			IHomeSiteNewsClassServ homeSiteNewsClassServ) {
		this.homeSiteNewsClassServ = homeSiteNewsClassServ;
	}



	public IHomeSiteNewsServ getHomeSiteNewsServImpl() {
		return homeSiteNewsServImpl;
	}



	public void setHomeSiteNewsServImpl(IHomeSiteNewsServ homeSiteNewsServImpl) {
		this.homeSiteNewsServImpl = homeSiteNewsServImpl;
	}



	public HtmlCreateObj getHtmlCreateObj() {
		return htmlCreateObj;
	}



	public void setHtmlCreateObj(HtmlCreateObj htmlCreateObj) {
		this.htmlCreateObj = htmlCreateObj;
	}



	public IUserManagerServ getUserManagerServ() {
		return userManagerServ;
	}



	public void setUserManagerServ(IUserManagerServ userManagerServ) {
		this.userManagerServ = userManagerServ;
	}
	
	
	

}
